/*
 * Copyright (c) 2002-2003 by OpenSymphony
 * All rights reserved.
 */
package com.ivo.security.authenticator;

import java.io.Serializable;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.ivo.dao.HibernateCaller;
import com.ivo.model.hr.Employee;

/**
 * A UserProvider is a plug-in implementation that allows a LoginManager to
 * access data in the back-end store.
 * 
 * <p>
 * A UserProvider implementation should always contain a public default
 * constructor. The init() method shall always be called before any other
 * methods.
 * </p>
 * 
 * <p>
 * Almost all methods return a boolean. This is to signify whether the operation
 * was successful.
 * </p>
 * 
 * @author David Yang
 * 
 */
public class UserProvider implements Serializable
{
	private static final long serialVersionUID = 1L;

	protected Log logger = LogFactory.getLog( this.getClass() );

	private static String USER_NAME_COLUMN = "id";

	private HibernateCaller dbCaller;

	/**
	 * Get user by user name
	 */
	public Employee getUser( String name ) {
		Employee user = getDbUser( name );
		return user;
	}

	private Employee getDbUser( String name ) {
		Employee user = (Employee) dbCaller.getObject( Employee.class, "id", name );
		return user;
	}

	public HibernateCaller getDbCaller() {
		return dbCaller;
	}

	public void setDbCaller( HibernateCaller dbCaller ) {
		this.dbCaller = dbCaller;
	}
}
